package com.mapaoer.user.dao;

import java.util.Optional;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.mapaoer.user.entity.User;

/**
 * 用户数据访问接口
 * 提供用户相关的数据库操作方法
 */
@Repository
public interface UserRepository extends BaseMapper<User> {

    @Select("SELECT * FROM sys_user WHERE username = #{username}")
    Optional<User> findByUsername(String username);

    @Select("SELECT CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END FROM sys_user WHERE username = #{username}")
    boolean existsByUsername(String username);

    @Select("SELECT CASE WHEN COUNT(*) > 0 THEN TRUE ELSE FALSE END FROM sys_user WHERE email = #{email}")
    boolean existsByEmail(String email);

    @Select("SELECT * FROM sys_user WHERE phone = #{phone}")
    Optional<User> findByPhone(String phone);

    @Select("SELECT * FROM sys_user WHERE wechat_open_id = #{openId}")
    Optional<User> findByWechatOpenId(String openId);

    @Select("SELECT * FROM sys_user WHERE alipay_user_id = #{userId}")
    Optional<User> findByAlipayUserId(String userId);


}